//1.渲染器
let renderer = new THREE.WebGLRenderer({
    antialias:true
});

renderer.setSize(window.innerWidth,window.innerHeight);

document.body.appendChild(renderer.domElement);

//2.场景
let scene = new THREE.Scene();

//3.照相机
let camera = new THREE.PerspectiveCamera(45,window.innerWidth/window.innerHeight,1,1000);

camera.position.z = 10;

camera.position.y = 10;

camera.position.x = -10;


camera.lookAt(scene.position);

scene.add(camera);

//4.物体

//创建球体的几何体
let sphereGemertry = new THREE.SphereGeometry(5,35,35);
let texture = new THREE.TextureLoader().load('./imgs/地球.jpg',() => {
    renderer.render(scene,camera);
});
//创建材质
let sphereMaterial = new THREE.MeshBasicMaterial({
    // color:0xff0000,
    // wireframe:true
    map:texture  //map设置纹理
})
//创建球体
let shpere = new THREE.Mesh(sphereGemertry,sphereMaterial);

scene.add(shpere);

//让地球转动
function render(){
    shpere.rotation.y += 0.01;
    requestAnimationFrame(render);
    renderer.render(scene,camera);
}

render();

//创建控制器  第一个参数：照相机  第二个参数：canvas
let controls = new THREE.OrbitControls(camera,renderer.domElement);
controls.addEventListener('change',() => {
    renderer.render(scene,camera);
})